//
//  CoreGraphics.swift
//  Adorbee
//
//  Created by amovision on 2024/11/26.
//

import UIKit

public extension Array where Element == CGFloat {
  var size: CGSize {
    switch count {
    case 2: CGSizeMake(self[0], self[1])
    case 1: CGSizeMake(self[0], self[0])
    default: .zero
    }
  }

  var point: CGPoint {
    switch count {
    case 2: CGPointMake(self[0], self[1])
    case 1: CGPointMake(self[0], self[0])
    default: .zero
    }
  }

  var rect: CGRect {
    switch count {
    case 4: CGRectMake(self[0], self[1], self[2], self[3])
    case 3: CGRectMake(self[0], self[0], self[1], self[2])
    case 2: CGRectMake(0, 0, self[0], self[1])
    case 1: CGRectMake(0, 0, self[0], self[0])
    default: .zero
    }
  }

  var inset: UIEdgeInsets {
    switch count {
    case 4: UIEdgeInsets(top: self[0], left: self[1], bottom: self[2], right: self[3])
    case 2: UIEdgeInsets(top: self[1], left: self[0], bottom: self[1], right: self[0])
    case 1: UIEdgeInsets(top: self[0], left: self[0], bottom: self[0], right: self[0])
    default: .zero
    }
  }
}

public extension CGSize {
  var rect: CGRect { CGRectMake(0, 0, width, height) }
}
